@extends('default.layouts.adminPublic')
@section('title', '编辑用户')

@section('content')
        <!--导航开始-->
<div class="crumb_warp">
    <i class="fa fa-home"></i> <a href="{{url('admin')}}">首页</a> &raquo; 用户管理
</div>
<!--导航结束-->

<!--结果集标题与导航组件 开始-->
<div class="result_wrap">
    <div class="result_title">
        <h3>修改用户</h3>
        @if(count($errors)>0)
            <div class="mark">
                @if(is_object($errors))
                    @foreach($errors->all() as $error)
                        <p>{{$error}}</p>
                    @endforeach
                @else
                    <p>{{$errors}}</p>
                @endif
            </div>
        @endif
    </div>
    <div class="result_content">
        <div class="short_wrap">
            <a href="{{url('admin/admin_user/create')}}"><i class="fa fa-plus"></i>添加用户</a>
            <a href="{{url('admin/admin_user')}}"><i class="fa fa-recycle"></i>用户列表</a>
        </div>
    </div>
</div>
<!--结果集标题与导航组件 结束-->

<div class="result_wrap">
    <form action="{{url('admin/admin_user/'.$AdminUser->id)}}" method="post" name="userForm"
          id="userForm" onsubmit="return checkForm('#userForm')">
        <input type="hidden" name="_method" value="put">
        <input type="hidden" name="id" value="{{$AdminUser->id}}">
        {{csrf_field()}}
        <table class="add_tab">
            <tbody>
            <tr>
                <th width="120">超级管理员：</th>
                <td>
                    <select name="is_super" style="width:200px;">
                        <option value="1" {{ $AdminUser->is_super == 1 ? 'selected':'' }}>是</option>
                        <option value="0" {{ $AdminUser->is_super == 0 ? 'selected':'' }}>否</option>
                    </select>
                </td>
            </tr>
            <tr>
                <th><i class="require">*</i> 用户名：</th>
                <td>
                    <input type="text" class="lg" name="name" value="{{ $AdminUser->name }}">
                </td>
            </tr>
            <tr>
                <th><i class="require">*</i> 邮箱：</th>
                <td>
                    <input type="text" class="lg" name="email" value="{{ $AdminUser->email }}">
                </td>
            </tr>
            <tr>
                <th>密码：</th>
                <td>
                    <input type="password" style="width:190px" class="lg"  name="password">
                </td>
            </tr>
            <tr>
                <th>确认密码：</th>
                <td>
                    <input type="password" style="width:190px" class="lg" name="password_confirmation">
                </td>
            </tr>
            {{--判断是不死超级管理员--}}
            @if($AdminUser->is_super == 1)
                <tr class="addroles">
                    <th width="120">所属角色：</th>
                    <td><strong style="font-size: 16px;">您好,您是超级管理员</strong></td>
                </tr>
            @else
                @if(is_object($admin_roles) && count($admin_roles) > 0)
                    @foreach($admin_roles as $k=> $v)
                        <tr class="addroles">
                            <th width="120">所属角色：</th>
                            <td>
                                <select name="role_id[]" id='role_id{{$v->id}}' style="width:200px;">
                                    <option value="">角色不限</option>
                                    @foreach($roles as $kk=> $vv)
                                        <option value="{{$vv->id}}">[{{$vv->name}}]{{$vv->display_name}}</option>
                                    @endforeach
                                </select>
                                @if($k == 0)
                                    <input type="button" id="addonerole" onclick="addOneRole(this)" value="添加一个角色">
                                @endif
                            </td>
                        </tr>
                        <script>document.getElementById('role_id' + '{{$v->id}}').value = '{{$v->id}}';</script>
                    @endforeach
                @else
                    <tr class="addroles">
                        <th width="120">所属角色：</th>
                        <td>
                            <select name="role_id[]" style="width:200px;">
                                <option value="">角色不限</option>
                                @foreach($roles as $kk=> $vv)
                                    <option value="{{$vv->id}}">[{{$vv->name}}]{{$vv->display_name}}</option>
                                @endforeach
                            </select>
                            <input type="button" id="addonerole" onclick="addOneRole(this)" value="添加一个角色">
                        </td>
                    </tr>
                @endif
            @endif
            <tr id="subrole">
                <th></th>
                <td>
                    <img src="" alt="" id="art_thumb_img" style="max-width: 350px; max-height:100px;">
                </td>
            </tr>

            <tr>
                <th></th>
                <td>
                    <input type="submit" value="提交">
                    <input type="button" class="back" onclick="history.go(-1)" value="返回">
                </td>
            </tr>
            </tbody>
        </table>
    </form>
</div>
{{--//添加一个角色--}}
<script type="text/JavaScript">
    function addOneRole(othis){
        var obj = $(othis).parents('tr').clone();
        obj.find('#addonerole').remove();
        if($('.addroles').size() <= 3){
            $('#subrole').before(obj);
        }else{
            layer.msg('角色属性个数不能大于4个', {icon: 5});
        }
    }
</script>
@endsection
